package com.wenzhi.studentservice.aopuse;

//import org.aopalliance.intercept.Joinpoint;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component // 没有也不报错
@Aspect // 没有也不报错
public class LoggerAspect {
    // Joinpoint 关联
    // @Before("execution(public int com.wenzhi.studentservice.aopuse.CalImpl.add(..))")
    @Before("execution(public int com.wenzhi.studentservice.aopuse.CalImpl.*(..))")
    public void func1(JoinPoint joinPoint) {
        String name = joinPoint.getSignature().getName();
        // Call to 'toString()' on array
        // System.out.println(name+"方法的参数是：" + joinPoint.getArgs().toString());
         System.out.println(name+"方法的参数是：" + Arrays.toString(joinPoint.getArgs()));
    }

    // @AfterReturning(value = "execution(public int com.wenzhi.studentservice.aopuse.CalImpl.add(..))", returning = "value")
    @AfterReturning(value = "execution(public int com.wenzhi.studentservice.aopuse.CalImpl.*(..))", returning = "value")
    public void func2(JoinPoint joinPoint, Object value) {
        String name = joinPoint.getSignature().getName();
        // System.out.println(name+"方法的返回值是：" + joinPoint.getTarget());
        System.out.println(name+"方法的返回值是：" + value);
    }
}
